package hjh.test;

import cn.hjh.pojo.Users;
import cn.hjh.service.UsersBiz;
import org.junit.Test;

import java.util.List;

public class sjlx {

    /* 第5章 HQL实用技术 */
    @Test
    /* HQL查询用户表的所有用户 */
    public void testUsers(){
        List<Users> usersList = new UsersBiz().findAllUsers();
        //遍历并输出结果
        for (Users users:usersList) {
            System.out.println("用户编号：" + users.getId());
            System.out.println("用户姓名：" + users.getName());
        }
    }

    @Test
    /*  查询用户名是。。。的用户 */
    public void testUsersByName(){
        List<Users> result = new UsersBiz().findUsersByName("admin");
        for (Users us:result) {
            System.out.println("用户编号：" + us.getId());
            System.out.println("用户姓名：" + us.getName());
        }
    }

    @Test
    /* 分页显示用户信息 */
    public void testUserByPage(){
        int pageNo = 1; //设置查询数据的起始位置
        int pageSize = 3;   //设置返回的结果数
        List<Users> usersList = new UsersBiz().findUsersByPage(pageNo,pageSize);
        for (Users us:usersList) {
            System.out.println("用户名：" + us.getName());
            System.out.println("电话:" + us.getTelephone());
        }
    }

    /* 第4章Hibernate入门 */
    @Test
    public void finUsersById(){
        Users users = new UsersBiz().UsersById(new Integer(77));
        System.out.println(users.getName());
    }

    @Test
    public void Add(){
        Users users=new Users();
        users.setName("bdqn");
        new UsersBiz().addNewUsers(users);
    }

    @Test
    public void Del(){
        new UsersBiz().deleteUsers(new Integer(60));
    }

    @Test
    public void updateByUsers(){
        Users users = new Users();
        users.setId(new Integer(77));
        users.setName("Accp6");
        new UsersBiz().updateUsers(users);
    }

    @Test
    public void mergeUpdate(){
        Users users = new Users();
        users.setId(new Integer(77));
        users.setName("accp8");
        new UsersBiz().mergeUsers(users);
    }
}
